package com.ling.pl.security.view.frame.main.register.logininfo;

import com.bstek.dorado.common.event.DefaultClientEvent;
import com.bstek.dorado.core.resource.ResourceManager;
import com.bstek.dorado.core.resource.ResourceManagerUtils;
import com.bstek.dorado.view.widget.Container;
import com.bstek.dorado.view.widget.form.Label;
import com.ling.pl.core.commons.exception.NoneLoginException;
import com.ling.pl.core.context.ContextHolder;
import com.ling.pl.security.model.DefaultUserVO;
import com.ling.pl.security.view.frame.main.IFrameShortcutActionRegister;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author bo.wang
 * @since 2013-2-6
 */
@Component
public class ShowLoginInfoShortcutRegister implements IFrameShortcutActionRegister {
    private static final ResourceManager resourceManager = ResourceManagerUtils
            .get(ShowLoginInfoShortcutRegister.class);
    @Value("${ling2.disableShowLoginInfoShortcutRegister:false}")
    private boolean disabled;

    public void registerToFrameTop(Container container) {
    }

    public void registerToStatusBar(Container container) {
        DefaultUserVO user = ContextHolder.getLoginUser();
        if (user == null) {
            throw new NoneLoginException("Please login first");
        }
        String name = user.getCname();
        if (StringUtils.isEmpty(name)) {
            name = user.getEname();
        }
        String info = user.getUsername();
        if (StringUtils.isNotEmpty(name)) {
            info = name + "(" + info + ")";
        }

        Label loginUserInfoLabel = new Label();
        loginUserInfoLabel.addClientEventListener("onRefreshDom", new DefaultClientEvent("arg.dom.style.lineHeight=arg.dom.style.height;"));
//		loginUserInfoLabel.setText(resourceManager.getString("ling2.core.d7/loginUserInfoLabel") + "："+info);
        loginUserInfoLabel.setText("登录人：" + "：" + info);
        container.addChild(loginUserInfoLabel);
    }

    public boolean isDisabled() {
        return disabled;
    }

    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

    public int order() {
        return 1;
    }

}
